#include<cstdio>
#include<iostream>
#include<vector>
using namespace std;
#define int long long 

class Union{
public:
	vector<int> parent;
	vector<int> rank;
	Union(int num){
		parent.resize(num);
		rank.resize(num,1);
		for(int i = 0; i < num ;i++){
			parent[i] = i;
		}
	}
	int find(int x){
		if(parent[x] != x){
			parent[x] = find(parent[x]);
		}
		return parent[x];
	}
	void unite(int x ,int y){
		int rx = find(x);
		int ry = find(y);
		if(rank[rx] < rank[ry]){
			parent[rx] = ry;
		}else if(rank[rx] > rank[ry] )
		{
			parent[ry] = rx;
		}
		else {
			parent[ry] = rx;
			rank[rx]++;
		}
		
	}
};

int n,m;
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	cin >> n >> m;
	Union u(n*2);
	for(int i=0;i<m;i++){
		char ch;
		int x,y;
		cin >> ch >> x >> y;
		if( ch == 'F'){
			u.unite(x,y);
		}else if (ch == 'E'){
//			if(u.find(x) == u.find(y)){
//				u.unite(x,y);
//			}
			u.unite(x + n,y);
			u.unite(x ,y + n);//反集合并
		}
	}
	int s = 0;
	for(int i=0;i<n;i++){
		if(u.find(i)==i) s++;
	}
	cout<<s;//祖先数就是团伙数
	return 0;
}
